﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Manager.gui
{
	/// <summary>
	/// Lógica de interacción para DialogNewAttribute.xaml
	/// </summary>
	public partial class DialogNewAttribute : Window
	{
		public string NameString { get; private set; }
		public string ShortName { get; private set; }
		public int Value { get; private set; }

		public DialogNewAttribute()
		{
			InitializeComponent();
		}
		public DialogNewAttribute(Attribute a)
		{
			InitializeComponent();
			NameString = a.Name;
			ShortName = a.ShortName;
			Value = a.Value;
			textBoxAttName.Text = NameString;
			textBoxAttShortName.Text = ShortName;
			textBoxAttValue.Text = Value.ToString();

		}
		private void okButton_Click(object sender, RoutedEventArgs e)
		{

			if (textBoxAttName.Text == "" || textBoxAttShortName.Text=="")
				return;
			else
			{
				NameString = textBoxAttName.Text;
				ShortName = textBoxAttShortName.Text;
				Value = Convert.ToInt32(textBoxAttValue.Text);
				this.DialogResult = true;
			}
		}

		private void textBoxAttValue_PreviewTextInput(object sender, TextCompositionEventArgs e)
		{
			e.Handled = !AreAllValidNumericChars(e.Text);
			base.OnPreviewTextInput(e);
		}

		private bool AreAllValidNumericChars(string str)
		{
			foreach (char c in str)
			{
				if (!Char.IsNumber(c)) return false;
			}

			return true;
		}

		private void cancelButton_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = false;
		}
	}
}
